package com.fjt.book_trade.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.fjt.book_trade.pojo.Assess;
import com.fjt.book_trade.pojo.Product;

public interface IProductDao {
	@Results({
		@Result(property = "product_id", column = "product_id"),
		@Result(property = "seller_name", column = "seller_name"),
		@Result(property = "product_name", column = "product_name"),
		@Result(property = "product_number", column = "product_number"),
		@Result(property = "product_price", column = "product_price"),
		@Result(property = "product_des", column = "product_des"),
		@Result(property = "product_type", column = "product_type")}
	)
	
	@Select("Select * from product")
	public List<Product> selectAllProduct();
	
	@Select("Select * from product where seller_name=#{username}")
	public List<Product> selectSellProduct(String username);
	
	
	@Select("Select * from product where product_id=#{product_id}")
	public Product findProductInfoById(int product_id);
	
	@Insert("Insert into product VALUES(#{product_id},#{seller_name},#{product_name},#{product_number},#{product_price},#{product_des},#{product_type})")
	public boolean addProduct(Product product);

	@Update("update product set product_number=product_number-#{number} where product_id=#{product_id}")
	public boolean subProductnumber(@Param("number")int number,@Param("product_id") int product_id);

	@Update("update product set product_number=product_number+#{number} where product_id=#{product_id}")
	public boolean addProductnumber(@Param("number")int number,@Param("product_id") int product_id);
	
	@Update("update product set product_name=#{product_name},seller_name=#{seller_name},product_price=#{product_price}"
			+ ",product_number=#{product_number},product_type=#{product_type},product_des=#{product_des}"
			+ " where product_id=#{product_id}")
	public boolean modifyProduct(Product produdct);
	
	@Select("select product_number from product where product_id=#{product_id}")
	public int checknumber(@Param("product_id") int product_id);
	
	@Select("select buyer_name,assess from p_order where product_id=#{product_id}")
	public List<Assess> getProductAssess(@Param("product_id")int product_id);
	
	@Select("select address from user where username=#{username}")
	public String selectaddressByUsername(String username);
}
